function LinkedList(){
	var Node = function (element){
		this.element = element;
		this.next = null;
	}
	var length = 0,
		head = null;
	//添加元素到链表尾部
	this.append = function (element){
		var node = new Node(element),
			current;
		if(head === null){
			head = node;
		}
		else{
			current = head;
			while (current.next){
				current = current.next;
			}
			current.next = node;
		}
		length++;
	}
	//插入某个元素
	this.insert = function (position,element){
		var node = new Node (element),
			current = head,
			previous,
			index = 0;
		if (position < 0 || position > length){
			return false;
		}
		if(position === 0){
			node.next = head;
			head = node;
		}
		else{
			while(index++ < position){
				previous = current;
				current = current.next;
			}
			node.next = current;
			previous.next = node;
		}
		length++;
		return true;
	}
	//某个元素在链表中的位置
	this.indexOf = function(element){
		var index = 0,
			current = head;
		while(current){
			if(element === current.element){
				return index;
			}
			index++;
			current = current.next;
		}
		return -1;
	}
	//移除链表中的某个位置的元素
	this.removeAt = function(position){
		var index = 0,
			position,
			current = head;
		if(position < 0 || position > length){
			return null;
		}
		if(position === 0){
			head = head.next;
		}
		else{
			while(index++ < position){
				previous = current;
				current = current.next;
			}
			previous.next = current.next;
		}
		length--;
		return current.element;
	}
	//获取链表的头部元素
	this.getHead = function (){
		return head.element;
	}
	this.size = function (){
		return length;
	}
	this.outPut = function (){
		var str = '',
			current = head;
		while(current){
			console.log(current.element);
			current = current.next;
		}
		return str;
	}

}
var linkList = new LinkedList();
linkList.append('hi');
linkList.append('good');
linkList.insert(0,'morning');
var len = linkList.size();
console.log(len);
var index = linkList.indexOf('morning');
console.log(index);
//linkList.removeAt(0);
linkList.outPut();
